# -*- coding: utf-8 -*-
import requests
import json

def func2(id,svlan,phyport,ip):
    

    # 请求URL
    url = "http://133.96.94.130:8080/ldims/liposs/vpnopen/hb/new/interface/newInterfaceAction!handPersonBack.action"

    # 请求头信息
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection": "keep-alive",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Cookie": "JSESSIONID=3FD6F327295833BA2445258F3899D401",  # 会话ID，过期需更新
        "Host": "133.96.94.130:8080",
        "Origin": "http://133.96.94.130:8080",
        "Referer": "http://133.96.94.130:8080/ldims/liposs/resource/mvopenorder/report.html",
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.200 Safari/537.36 Qaxbrowser"
    }

    # 表单提交数据
    data = {
        "requestId": id,  # 请求ID
        "doubleIs": "1",                  # 单纤/双纤标识
        "status": "-1",                   # 状态
        "descr": "失败",                  # 描述信息
        "device_ip": ip,      # 设备IP
        "phyport": phyport,             # 物理端口
        "svlan": svlan,                  # 外层VLAN
        "cvlan": "",                      # 内层VLAN（空值）
        "remark1": "0",                   # 备注1
        "openType": "102"                 # 操作类型
    }

    try:
        # 发送POST请求
        response = requests.post(
            url=url,
            headers=headers,
            data=data,
            timeout=15  # 超时时间设置为15秒
        )
        
        # 处理响应结果
        if response.status_code == 200:
            try:
                # 尝试解析JSON响应
                result = response.json()
                print("提交成功，返回结果：")
                print(json.dumps(result, ensure_ascii=False, indent=2))
            except json.JSONDecodeError:
                # 非JSON格式响应直接输出
                print("提交成功，返回内容：")
                print(response.text)
        else:
            print("提交失败，状态码：{}".format(response.status_code))
            print("响应内容：{}".format(response.text))

    except requests.exceptions.RequestException as e:
        print("请求发生异常：{}".format(e))



def func1(id,svlan,phyport,ip):
    
    # 请求URL
    url = "http://133.96.94.130:8080/ldims/liposs/vpnopen/hb/new/interface/newInterfaceAction!qryPersonBackOrder.action"

    # 请求头（从提供的请求详情中提取，模拟浏览器环境）
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection": "keep-alive",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "Cookie": "JSESSIONID=3FD6F327295833BA2445258F3899D401",  # 会话ID，过期需重新获取
        "Host": "133.96.94.130:8080",
        "Origin": "http://133.96.94.130:8080",
        "Referer": "http://133.96.94.130:8080/ldims/liposs/resource/mvopenorder/report.html",
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.200 Safari/537.36 Qaxbrowser"
    }

    # 表单数据（仅包含请求参数requestId）
    data = {
        "requestId": id  # 可根据需求修改为目标requestId
    }

    try:
        # 发送POST请求
        response = requests.post(url, headers=headers, data=data, timeout=10)
        
        # 检查响应状态
        if response.status_code == 200:
            # 尝试解析JSON数据（假设返回格式为JSON）
            try:
                result = response.json()
                func2(id,svlan,phyport,ip)
                
            except json.JSONDecodeError:
                # 若返回非JSON格式，直接打印文本内容
                print("请求成功，返回内容（非JSON）：")
                print(response.text)
        else:
            print("请求失败，状态码：{}".format(response.status_code))
            print("响应内容：{}".format(response.text))

    except requests.exceptions.RequestException as e:
        print("请求异常：{}".format(e))


# 请求URL
url = "http://133.96.94.130:8080/ldims/liposs/resource/mvopenorder/data!qryOrder.action"

# 请求头
headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Connection": "keep-alive",
    "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    "Cookie": "JSESSIONID=3FD6F327295833BA2445258F3899D401",
    "Host": "133.96.94.130:8080",
    "Origin": "http://133.96.94.130:8080",
    "Referer": "http://133.96.94.130:8080/ldims/liposs/resource/mvopenorder/report.html",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.200 Safari/537.36 Qaxbrowser"
}

# 表单数据
data = {
    "begin": "2025-08-22",
    "end": "2025-08-22",
    "lastTime": "2025-08-22",
    "cityId": "-1",
    "receiptStatus": "-1",
    "status": "-1",
    "bussId": "",
    "userName": "",
    "openType": "-1",
    "orderSource": "-1",
    "vpnInstance": "",
    "chargebackReason": "-1",
    "totalItems": "31",
    "curPage_splitPage": "1",
    "maxSize": "3",
    "num_splitPage": "130",
    "change": "1"
}

try:
    # 发送POST请求
    response = requests.post(url, headers=headers, data=data, timeout=10)
    
    # 检查响应状态
    if response.status_code == 200:
        # 解析JSON数据
        result = response.json()
        print("请求成功，返回数据：")
        for obj in result["dataList"]:
            id = obj["requestId"]
            svlan = obj["svlan"]
            phyport = obj["phyport"]
            ip = obj["deviceIp"]
            print(id,svlan)
            func1(id,svlan,phyport,ip)

    else:
        print("请求失败，状态码：{}".format(response.status_code))
        print("响应内容：{}".format(response.text))

except requests.exceptions.RequestException as e:
    print("请求异常：{}".format(e))
